home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / TREEWIND.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  23KB  |  866 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.24  $
  6. //
  7. // Declares TTreeWindow, TTreeNode, and TTreeItem
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_TREEWIND_H)
  10. #define OWL_TREEWIND_H
  11.  
  12. #if !defined(OWL_COMMCTRL_H)
  13. # include <owl/commctrl.h>
  14. #endif
  15. #if !defined(OWL_LISTBOX_H)
  16. # include <owl/listbox.h>
  17. #endif
  18. #if defined(BI_PLAT_WIN16)
  19. # include <owl/treewn16.h>
  20. #else
  21.  
  22. #if defined(BI_NAMESPACE)
  23. namespace OWL {
  24. #endif
  25.  
  26. // Generic definitions/compiler options (eg. alignment) preceeding the 
  27. // definition of classes
  28. #include <services/preclass.h>
  29.  
  30. class _OWLCLASS TTreeWindow;
  31. class _OWLCLASS TTreeNode;
  32. class _OWLCLASS TTreeItem;
  33.  
  34. class _OWLCLASS TTwHitTestInfo;
  35. class _OWLCLASS TTwComparator;
  36.  
  37. //
  38. // class TTreeItem
  39. // ~~~~~ ~~~~~~~~~
  40. // Used to represent the data to be stored in the TTreeWindow.
  41. //
  42. class _OWLCLASS TTreeItem : public TV_ITEM {
  43.   public:
  44.     TTreeItem();               // this is called by some TTreeNode constructors
  45.     TTreeItem(TV_ITEM item);
  46.     TTreeItem(const char far*, int len = 0);
  47.     TTreeItem(const char far*, int index, int selIndex);
  48.  
  49.     // Initialize the text
  50.     //
  51.     void SetText(const char far*, int len = -1);
  52.     void GetText(char far*, int len);
  53.  
  54.     // Set/Get the "magic cookie"
  55.     //
  56.     void      SetHTreeItem(HTREEITEM hItem);
  57.     HTREEITEM GetHTreeitem() const;
  58.  
  59.     // Set the imagelist index
  60.     //
  61.     void SetImageIndex(int index);
  62.  
  63.     // Set the selected image index
  64.     //
  65.     void SetSelectedImageIndex(int index);
  66.  
  67.     // Store additional information
  68.     //
  69.     void   SetItemData(uint32);
  70.     uint32 GetItemData() const;
  71.  
  72.   protected:
  73.     void Init();
  74. };
  75.  
  76. //
  77. // class TTwComparator
  78. // ~~~~~ ~~~~~~~~~~~~~
  79. // A base class for comparisons to sort items.
  80. //
  81. class _OWLCLASS TTwComparator {
  82.   public:
  83.     // return value is < 0 if item1 < item2
  84.     //                 = 0 if item1 == item2
  85.     //                 > 0 if item1 > item2
  86.     // lParam is user-defined value, pass to TTreeNode::SortChildren
  87.     //
  88.     virtual int Compare(uint32 item1, uint32 item2, uint32 lParam) const;
  89. };
  90.  
  91. //
  92. // class TTreeNode
  93. // ~~~~~ ~~~~~~~~~
  94. // Use this class to navigate the TTreeWindow.
  95. // Each node conceptually contains a pointer to a TTreeItem.
  96. //
  97. class _OWLCLASS TTreeNode {
  98.   public:
  99.  
  100.     // How to insert the node
  101.     //
  102.     enum THowToInsert {
  103.       First           = (int)TVI_FIRST,      // First child
  104.       Last            = (int)TVI_LAST,       // Last child
  105.       Sort            = (int)TVI_SORT        // Sort order
  106.     };
  107.  
  108.     // Constructors
  109.     //
  110.  
  111.     // The next two constructors are for creating new nodes.  Both create only
  112.     // the C++ TTreeNode object.  Call SetItem to make the new node appear in
  113.     // the treeview control.
  114.     //
  115.     TTreeNode(TTreeWindow& tree, const char far* text);
  116.     TTreeNode(TTreeWindow& tree, const char far* text, int index, int selIndex);
  117.  
  118.     // The next two constructors create a node object to represent a node
  119.     // that already exists.
  120.  
  121.     // Use this constructor in event handlers. The event message carries
  122.     // a TTwNotify structure.
  123.     //
  124.     TTreeNode(TTreeWindow& tree, TV_ITEM item);
  125.  
  126.     // This constructor is useful for enumerating nodes on a tree.
  127.     // Passing just the first parameter creates the node object for
  128.     // the tree's root, a good starting point.
  129.     //
  130.     TTreeNode(TTreeWindow& tree, HTREEITEM hItem = TVI_ROOT);
  131.  
  132.     // Construct the node neighboring a given node.  A TVGN_* flag indicates
  133.     // whether to create the next, previous, parent, or first child node.
  134.     //
  135.     TTreeNode(const TTreeNode& node, uint32 flag);
  136.  
  137.     // Copy constructor. Used by functions such as TTreeWindow::GetRoot
  138.     // that return a TTreeNode by value.  
  139.     //
  140.     TTreeNode(const TTreeNode&);
  141.  
  142.     // Assignment operator
  143.     // 
  144.     TTreeNode& operator=(const TTreeNode& other);
  145.  
  146.     // Navigation
  147.     //
  148.     TTreeNode GetParent() const;
  149.     TTreeNode GetChild() const;
  150.     TTreeNode GetNextSibling() const;
  151.     TTreeNode GetPrevSibling() const;
  152.     TTreeNode GetNextVisible() const;
  153.     TTreeNode GetPrevVisible() const;
  154.     TTreeNode GetNextItem(uint32 flag) const;
  155.  
  156.     // Adding and deleting items from the tree
  157.     //
  158.     TTreeNode AddChild(const TTreeNode& node) const;
  159.     TTreeNode AddSibling(const TTreeNode& node) const;
  160.     TTreeNode InsertChild(const TTreeNode& node, THowToInsert how) const;
  161.     TTreeNode InsertItem(const TTreeNode& node) const;
  162.     bool      Delete(void);
  163.  
  164.     // These older add/delete methods use TTreeItem.  They have
  165.     // been replaced by the versions that operate on the node
  166.     // itself.  They are retained for backward compatibility.
  167.     //
  168.     TTreeNode AddChild(const TTreeItem&) const;         // add item at end
  169.     TTreeNode AddSibling(const TTreeItem&) const;
  170.     TTreeNode InsertChild(const TTreeItem&, THowToInsert) const;
  171.     TTreeNode InsertItem(const TTreeItem&) const;
  172.  
  173.     // These operations affect only information stored in the node object,
  174.     // not the Windows treeview control itself.
  175.     //
  176.     void       SetMask(uint mask);
  177.     uint       GetMask(void) const;
  178.     void       SetStateMask(uint mask);
  179.     uint       GetStateMask(void) const;
  180.     void       SetHTreeItem(HTREEITEM hItem);
  181.     HTREEITEM  GetHTreeItem() const;
  182.  
  183.     // These operations send messages to the control.  The message delivery
  184.     // might fail, so they return bool.
  185.     //
  186.     bool       SetHasChildren(int hasChildren, bool sendNow = true);
  187.     bool       GetHasChildren(int& hasChildren, bool getNew = true);
  188.     bool       SetState(uint state, bool sendNow = true);
  189.     bool       GetState(uint& state, bool getNew = true);
  190.     bool       SetImageIndex(int index, bool sendNow = true);
  191.     bool       SetSelectedImageIndex(int index, bool sendNow = true);
  192.     bool       SetItemData(uint32 data, bool sendNow = true);
  193.     bool       GetItemData(uint32& data, bool getNew = true);
  194.     bool       GetItemRect(TRect& rect, bool textOnly = true) const;
  195.     
  196.     // Set/GetText store the text in the node's internal buffer so the
  197.     // caller doesn't have to worry about string length and buffer
  198.     // ownership.
  199.     //
  200.     bool       SetText(const char far* text, bool sendNow = true);
  201.  
  202.     // This GetText copies the string into the caller's buffer
  203.     //
  204.     bool       GetText(char far* text, uint length, bool getNew = false);
  205.  
  206.     // This GetText returns a pointer to the node's own internal text buffer
  207.     //
  208.     char far*  GetText(bool getNew = false);
  209.  
  210.     // The default cache size is _MAX_PATH.  The cache size is used only in 
  211.     // Get functions when allocating buffers for strings received from the
  212.     // control. For a control with strings longer than _MAX_PATH, be sure to
  213.     // bump the cache size before calling Get.  (The buffer size is kept
  214.     // in a static variable, so any alteration affects all TTreeNodes.)
  215.     //
  216.     void       SetCacheSize(uint size);
  217.     void       FlushCache(void);              // empty this node's text cache
  218.  
  219.     // The Set/Get accessors for individual node attributes send a message
  220.     // to put data into, or receive data from, the treeview control.  The
  221.     // sendNow and getNew parameters make it possible to accumulate requests
  222.     // and send them in a single message.
  223.     //
  224.     //    SetItemData(myData, false);   // this sends no message
  225.     //    SetText("MyText", false);     // this sends no message
  226.     //    SetHasChildren(1, true);      // this sends all 3 attributes
  227.  
  228.     // The recommended way to get and set attributes is with the access 
  229.     // functions for individual attributes.  Those commands call these
  230.     // two function to interact with the Windows control.
  231.     // 
  232.     bool       GetItem(void);
  233.     bool       SetItem(void);
  234.  
  235.     // Preserved for 5.0 code that still uses the TTreeItem struct.
  236.     //
  237.     bool       GetItem(TTreeItem* item);
  238.     bool       SetItem(TTreeItem* item);
  239.  
  240.     // Miscellaneous
  241.     //
  242.     HIMAGELIST CreateDragImage();
  243.     HWND       EditLabel();
  244.     bool       EnsureVisible();
  245.     bool       ExpandItem(uint32 flag);
  246.     bool       SelectItem(uint32 flag);
  247.  
  248.     // Sort the nodes of the subtree
  249.     //
  250.     bool       SortChildren(bool recurse = false);
  251.     bool       SortChildren(const TTwComparator& Comparator, bool recurse = false,
  252.                             uint32 extraParam = 0);
  253.  
  254.     // The HTREEITEM() operator is useful when enumerating nodes.
  255.     // For example, to enumerate all the top-level nodes:
  256.     //
  257.     // for (TTreeNode& node = GetRoot().GetChild();
  258.     //      node;               // evaluates to null handle after last node
  259.     //      node = node.GetNextSibling())
  260.     // { /* loop code */ };
  261.     //                          
  262.     operator  HTREEITEM() const;
  263.  
  264.     // Codes for TTreeNode (TExpandCode, TNextCode)
  265.     //
  266.     // Retained for compatiblity, but no longer recommended.
  267.     // Use the TVE_ and TVGN_ constants directly instead of
  268.     // these enums.
  269.  
  270.     // How to expand the item.
  271.     //
  272.     enum TExpandCode {
  273.       Collapse        = TVE_COLLAPSE,       // Always collapse
  274.       Expand          = TVE_EXPAND,         // Always expand
  275.       Toggle          = TVE_TOGGLE,         // Toggle between collapse and expand
  276.       CollapseReset   = TVE_COLLAPSERESET   // Collapse this node and all children
  277.     };
  278.  
  279.     // How to retrieve the next node
  280.     //
  281.     enum TNextCode {
  282.       Root            = TVGN_ROOT,              // Get the root node
  283.       Next            = TVGN_NEXT,              // Get the next sibling
  284.       Previous        = TVGN_PREVIOUS,          // Get the prev sibling
  285.       Parent          = TVGN_PARENT,            // Get the parent of this node
  286.       Child           = TVGN_CHILD,             // Get the first child
  287.       FirstVisible    = TVGN_FIRSTVISIBLE,      // Get the first visible item
  288.       NextVisible     = TVGN_NEXTVISIBLE,       // Get the next visible item
  289.       PreviousVisible = TVGN_PREVIOUSVISIBLE,   // Get the prev visible item
  290.       DropHilite      = TVGN_DROPHILITE,        // Get the item that is the drop target
  291.       Caret           = TVGN_CARET              // Get the item with the caret
  292.     };
  293.  
  294.   protected:
  295.     TTreeItem ItemStruct;             // contains a TV_ITEM with HTREEITEM
  296.     TTreeWindow* TreeView;            // wrapper for item of this tree
  297.  
  298.   private:
  299.     TAPointer<char> CacheText;        // buffer for node text
  300.     static uint NodeTextCacheSize;    // size of text caching buffer
  301.  
  302.     // Clone function used by copy constructor
  303.     //
  304.     TTreeNode& CopyNode(const TTreeNode& node);
  305.  
  306.     // default constructor disallowed
  307.     //
  308.     TTreeNode(void);      
  309. };
  310.  
  311. //
  312. // class TTreeWindow
  313. // ~~~~~ ~~~~~~~~~~~
  314. // Encapsulates the TreeView common control.
  315. // A TreeWindow displays information in a hierarchical manner.
  316. // Each item in the tree can contain text and a picture.
  317. //
  318. class _OWLCLASS TTreeWindow : public TListBox {
  319.   public:
  320.     // The type of the image list
  321.     //
  322.     enum TImageListType {
  323.       Normal = TVSIL_NORMAL,    // Normal imagelist for selected and non-selected items
  324.       State  = TVSIL_STATE      // Imagelist contains images for user-defined states
  325.     };
  326.  
  327.     // Constructors and destructor
  328.     //
  329.     TTreeWindow(TWindow* parent, int id, int x, int y, int w, int h,
  330.                 uint32 style = 0, TModule* module = 0);
  331.     TTreeWindow(TWindow* parent, int resourceId, TModule* module = 0);
  332.    ~TTreeWindow();
  333.  
  334.     // Style management
  335.     //
  336.     void SetStyle(uint32 style);
  337.     bool HasStyle(uint32 style);
  338.  
  339.     // TreeNode retrieval
  340.     //
  341.     TTreeNode GetRoot();
  342.     TTreeNode GetSelection();
  343.     TTreeNode GetDropHilite();
  344.     TTreeNode GetFirstVisible();
  345.  
  346.     // Indent level
  347.     //
  348.     uint GetIndent();
  349.     void SetIndent(uint);
  350.  
  351.     // Image list
  352.     //
  353.     HIMAGELIST GetImageList(TImageListType type);
  354.     HIMAGELIST SetImageList(TImageListType type, HIMAGELIST newList);
  355.  
  356.     // Miscellaneous
  357.     //
  358.     bool DeleteAllItems();
  359.     uint GetItemCount();
  360.     uint GetVisibleCount();
  361.     HWND GetEditControl();
  362.  
  363.     // Provided for API compatability, use TTreeNode instead.
  364.     // These functions are called from TTreeNode
  365.     //
  366.     void Update();
  367.     bool SortChildren(PFNTVCOMPARE, HTREEITEM parent, bool recurse = false, uint32 lParam = 0);
  368.     bool SortChildren(HTREEITEM item, bool recurse = false);
  369.     bool Delete(HTREEITEM);
  370.     bool EnsureVisible(HTREEITEM);
  371.     bool ExpandItem(uint32 flag, HTREEITEM);
  372.     bool SelectItem(uint32 flag, HTREEITEM hItem);
  373.     HWND EditLabel(HTREEITEM item);
  374.     HTREEITEM HitTest(TTwHitTestInfo* info);
  375.     HTREEITEM GetNextItem(uint32 nc, HTREEITEM);
  376.     HTREEITEM InsertItem(TV_INSERTSTRUCT far*);
  377.     HIMAGELIST CreateDragImage(HTREEITEM item);
  378.  
  379.     // Styles for TTreeWindow
  380.     //
  381.     // Retained for compatiblity, but no longer recommended.
  382.     // Use the TVS_* style constants directly instead of this enum.
  383.     //
  384.     enum TStyle {
  385.       twsNone            = 0,                     // No style
  386.       twsHasButtons      = TVS_HASBUTTONS,        // Each parent has a button
  387.                                                   // for toggling collapse and expand
  388.       twsHasLines        = TVS_HASLINES,          // There are lines between nodes
  389.       twsLinesAtRoot     = TVS_LINESATROOT,       // There are lines at the root
  390.       twsEditLabels      = TVS_EDITLABELS,        // Text labels for items can be edited
  391.       twsDisableDragDrop = TVS_DISABLEDRAGDROP,   // Do not allow drag and drop
  392.       twsShowSelAlways   = TVS_SHOWSELALWAYS,     // Always keep the selection visible
  393.                                                   // scroll if needed
  394.     };
  395.  
  396.   protected:
  397.     // Override TWindow virtual member functions
  398.     //
  399.     char far* GetClassName();
  400.  
  401.   protected_data:
  402.     uint32 Style;
  403.  
  404.   private:
  405.     // Hidden to prevent accidental copying or assignment
  406.     //
  407.     TTreeWindow(const TTreeWindow&);
  408.     TTreeWindow& operator=(const TTreeWindow&);
  409.  
  410.   DECLARE_STREAMABLE(_OWLCLASS, TTreeWindow, 1);
  411. };
  412.  
  413. // Generic definitions/compiler options (eg. alignment) following the 
  414. // definition of classes
  415. #include <services/posclass.h>
  416.  
  417. #if defined(BI_NAMESPACE)
  418. } // namespace OWL
  419. #endif
  420.  
  421. //----------------------------------------------------------------------------
  422. // Inline implementation
  423. //
  424.  
  425. //
  426. // Default comparison function that makes every item equal to every
  427. // other item.
  428. // Derived classes should override this to return proper sorting codes.
  429. //
  430. inline int
  431. TTwComparator::Compare(uint32 item1, uint32 item2, uint32 lParam) const
  432. {
  433.   return 0;
  434. }
  435.  
  436. //
  437. // Return the magic cookie used by the control associated with the item
  438. //
  439. inline
  440. TTreeNode::operator HTREEITEM() const
  441. {
  442.   return ItemStruct.hItem;
  443. }
  444.  
  445. //
  446. // Return the HWND of the edit control to change the text
  447. //
  448. inline HWND
  449. TTreeNode::EditLabel()
  450. {
  451.   return TreeView->EditLabel(*this);
  452. }
  453.  
  454. //
  455. // Return the image list used for a dragging purposes
  456. //
  457. inline HIMAGELIST
  458. TTreeNode::CreateDragImage()
  459. {
  460.   return TreeView->CreateDragImage(*this);
  461. }
  462.  
  463. //
  464. // Makes sure the item is visible.
  465. // Scroll the items if necessary.
  466. //
  467. inline bool
  468. TTreeNode::EnsureVisible()
  469. {
  470.   return TreeView->EnsureVisible(*this);
  471. }
  472.  
  473. //
  474. // Expand or contract a parent node.
  475. // Similar to the user clicking on the '-' or '+' area of the control.
  476. //
  477. inline bool
  478. TTreeNode::ExpandItem(uint32 flag)
  479. {
  480.   return TreeView->ExpandItem(flag, (HTREEITEM)*this);
  481. }
  482.  
  483. //
  484. // Make the next item selected.
  485. //
  486. inline bool
  487. TTreeNode::SelectItem(uint32 flag)
  488. {
  489.   return TreeView->SelectItem(flag, *this);
  490. }
  491.  
  492. //
  493. // Return the next item.
  494. //
  495. inline TTreeNode
  496. TTreeNode::GetNextItem(uint32 flag) const
  497. {
  498.   return TTreeNode(*TreeView, TreeView->GetNextItem(flag, *this));
  499. }
  500.  
  501. inline TTreeNode
  502. TTreeNode::InsertChild(const TTreeNode& node, THowToInsert how) const
  503. {
  504.   return InsertChild(node.ItemStruct, how);
  505. }
  506.  
  507. inline TTreeNode
  508. TTreeNode::InsertItem(const TTreeNode& node) const
  509. {
  510.   return InsertItem(node.ItemStruct);
  511. }
  512.  
  513. inline TTreeNode
  514. TTreeNode::AddChild(const TTreeNode& node) const
  515. {
  516.   return InsertChild(node.ItemStruct, Last);
  517. }
  518.  
  519. inline TTreeNode
  520. TTreeNode::AddChild(const TTreeItem& item) const
  521. {
  522.   return InsertChild(item, Last);
  523. }
  524.  
  525. //
  526. // Return the parent of the current node.
  527. //
  528. inline TTreeNode
  529. TTreeNode::GetParent() const
  530. {
  531.   return GetNextItem(Parent);
  532. }
  533.  
  534. //
  535. // Get the first child of the current node.
  536. //
  537. inline TTreeNode
  538. TTreeNode::GetChild() const
  539. {
  540.   return GetNextItem(Child);
  541. }
  542.  
  543. //
  544. // Return the next sibling.
  545. //
  546. inline TTreeNode
  547. TTreeNode::GetNextSibling() const
  548. {
  549.   return GetNextItem(Next);
  550. }
  551.  
  552. //
  553. // Return the previous sibling.
  554. //
  555. inline TTreeNode
  556. TTreeNode::GetPrevSibling() const
  557. {
  558.   return GetNextItem(Previous);
  559. }
  560.  
  561. //
  562. // Return the next visible item.
  563. //
  564. inline TTreeNode
  565. TTreeNode::GetNextVisible() const
  566. {
  567.   return GetNextItem(NextVisible);
  568. }
  569.  
  570. //
  571. // Return the next previous item.
  572. //
  573. inline TTreeNode
  574. TTreeNode::GetPrevVisible() const
  575. {
  576.   return GetNextItem(PreviousVisible);
  577. }
  578.  
  579. //
  580. // Sort the children of this node
  581. //
  582. inline bool
  583. TTreeNode::SortChildren(bool recurse)
  584. {
  585.   return TreeView->SortChildren(*this, recurse);
  586. }
  587.  
  588. inline void
  589. TTreeNode::SetMask(uint mask)
  590. {
  591.   ItemStruct.mask = mask;
  592. }
  593.  
  594. inline uint       
  595. TTreeNode::GetMask() const
  596. {
  597.   return ItemStruct.mask;
  598. }
  599.  
  600. inline void
  601. TTreeNode::SetStateMask(uint mask)
  602. {
  603.   ItemStruct.stateMask = mask;
  604. }
  605.  
  606. inline uint
  607. TTreeNode::GetStateMask() const
  608. {
  609.   return ItemStruct.stateMask;
  610. }
  611.  
  612. //
  613. //  Set and Get the node's item handle.
  614. //
  615.  
  616. inline void
  617. TTreeNode::SetHTreeItem(HTREEITEM hItem)
  618. {
  619.   ItemStruct.SetHTreeItem(hItem);
  620. }
  621.  
  622. inline HTREEITEM  
  623. TTreeNode::GetHTreeItem() const
  624. {
  625.   return ItemStruct.GetHTreeitem();
  626. }
  627.  
  628. //
  629. // Set the item associated with this node
  630. //
  631. inline bool
  632. TTreeNode::SetItem(TTreeItem* item)
  633. {
  634.   PRECONDITION(TreeView);
  635.   PRECONDITION(item && item->mask);
  636.   item->SetHTreeItem(*this);
  637.   return TreeView->SendMessage(TVM_SETITEM, 0, TParam2(item)) != 0;
  638. }
  639.  
  640. //
  641. //
  642. //
  643. inline bool
  644. TTreeNode::SetItem()
  645. {
  646.   PRECONDITION(TreeView);
  647.   PRECONDITION(ItemStruct.mask);
  648.   return TreeView->SendMessage(TVM_SETITEM, 0, TParam2(&ItemStruct)) != 0;
  649. }
  650.  
  651. //
  652. // Return the item associated with the node
  653. //
  654. inline bool
  655. TTreeNode::GetItem(TTreeItem* item)
  656. {
  657.   PRECONDITION(ItemStruct.hItem);
  658.   PRECONDITION(TreeView);
  659.   item->SetHTreeItem(*this);
  660.   return TreeView->SendMessage(TVM_GETITEM, 0, TParam2(item)) != 0;
  661. }
  662.  
  663. //
  664. // Update the item information in the node.
  665. // What's set in the mask determines what will be retrieved.
  666. // Unless the user has explicitly called SetMask, the call should
  667. // retrieve everything.
  668. //
  669. inline bool
  670. TTreeNode::GetItem()
  671. {
  672.   PRECONDITION(ItemStruct.mask & TVIF_HANDLE);
  673.   PRECONDITION(ItemStruct.hItem);
  674.   PRECONDITION(TreeView);
  675.   return TreeView->SendMessage(TVM_GETITEM, 0, TParam2(&ItemStruct)) != 0;
  676. }
  677.  
  678. //----------------------------------------------------------------------------
  679. // TTreeWindow
  680.  
  681. //
  682. // Return the item that contains the point.
  683. //
  684. inline HTREEITEM
  685. TTreeWindow::HitTest(TTwHitTestInfo* info)
  686. {
  687.   return (HTREEITEM)SendMessage(TVM_HITTEST, 0, TParam2(info));
  688. }
  689.  
  690. //
  691. // Set the image list used by the control.
  692. //
  693. inline HIMAGELIST
  694. TTreeWindow::SetImageList(TImageListType type, HIMAGELIST newList)
  695. {
  696.   return (HIMAGELIST)SendMessage(TVM_SETIMAGELIST, TParam1(type), TParam2(newList));
  697. }
  698.  
  699. //
  700. // Return the image list used by the control.
  701. //
  702. inline HIMAGELIST
  703. TTreeWindow::GetImageList(TImageListType type)
  704. {
  705.   return (HIMAGELIST)SendMessage(TVM_GETIMAGELIST, TParam1(type));
  706. }
  707.  
  708. //
  709. // Create a drag image.
  710. //
  711. inline HIMAGELIST
  712. TTreeWindow::CreateDragImage(HTREEITEM item)
  713. {
  714.   return (HIMAGELIST)SendMessage(TVM_CREATEDRAGIMAGE, 0, TParam2(item));
  715. }
  716.  
  717. //
  718. // Return the edit control used for editing the text.
  719. //
  720. inline HWND
  721. TTreeWindow::GetEditControl()
  722. {
  723.   return (HWND)SendMessage(TVM_GETEDITCONTROL);
  724. }
  725.  
  726. //
  727. // Enable the user to edit the text of an item.
  728. //
  729. inline HWND
  730. TTreeWindow::EditLabel(HTREEITEM item)
  731. {
  732.   return (HWND)SendMessage(TVM_EDITLABEL, 0, TParam2(item));
  733. }
  734.  
  735. //
  736. // Return the next item.
  737. //
  738. inline HTREEITEM
  739. TTreeWindow::GetNextItem(uint32 nc, HTREEITEM hItem)
  740. {
  741.   if (hItem == TVI_ROOT)  // Workaround for Win95 bug.
  742.     hItem = 0;
  743.   return (HTREEITEM)SendMessage(TVM_GETNEXTITEM, nc, TParam2(hItem));
  744. }
  745.  
  746. //
  747. // Delete the item.
  748. //
  749. inline bool
  750. TTreeWindow::Delete(HTREEITEM hItem)
  751. {
  752.   return SendMessage(TVM_DELETEITEM, 0, TParam2(hItem)) != 0;
  753. }
  754.  
  755. //
  756. // Makes sure the item is visible.
  757. //
  758. inline bool
  759. TTreeWindow::EnsureVisible(HTREEITEM hItem)
  760. {
  761.   return SendMessage(TVM_ENSUREVISIBLE, 0, TParam2(hItem)) != 0;
  762. }
  763.  
  764. //
  765. // Expand and contract the parent node.
  766. //
  767. inline bool
  768. TTreeWindow::ExpandItem(uint32 flag, HTREEITEM hItem)
  769. {
  770.   return SendMessage(TVM_EXPAND, flag, TParam2(hItem)) != 0;
  771. }
  772.  
  773. //
  774. // Select the next item.
  775. //
  776. inline bool
  777. TTreeWindow::SelectItem(uint32 flag, HTREEITEM hItem)
  778. {
  779.   return SendMessage(TVM_SELECTITEM, flag, TParam2(hItem)) != 0;
  780. }
  781.  
  782. //
  783. // Insert an item.
  784. //
  785. inline HTREEITEM
  786. TTreeWindow::InsertItem(TV_INSERTSTRUCT far* tvis)
  787. {
  788.   return (HTREEITEM)SendMessage(TVM_INSERTITEM, 0, TParam2(tvis));
  789. }
  790.  
  791. //
  792. // Remove all items from the control
  793. //
  794. inline bool
  795. TTreeWindow::DeleteAllItems()
  796. {
  797.   return Delete(TVI_ROOT);
  798. }
  799.  
  800. //
  801. // Return the number of items in the control.
  802. //
  803. inline uint
  804. TTreeWindow::GetItemCount()
  805. {
  806.   return (uint)SendMessage(TVM_GETCOUNT);
  807. }
  808.  
  809. //
  810. // Return the number of the fully visible items in the control.
  811. //
  812. inline uint
  813. TTreeWindow::GetVisibleCount()
  814. {
  815.   return (uint)SendMessage(TVM_GETVISIBLECOUNT);
  816. }
  817.  
  818. //
  819. // Return the number of pixels per indent level.
  820. //
  821. inline uint
  822. TTreeWindow::GetIndent()
  823. {
  824.   return (uint)SendMessage(TVM_GETINDENT);
  825. }
  826.  
  827. //
  828. // Set the number of pixels per indent level.
  829. //
  830. inline void
  831. TTreeWindow::SetIndent(uint indent)
  832. {
  833.   SendMessage(TVM_SETINDENT, indent);
  834. }
  835.  
  836. //
  837. // Sort the children of 'item'.
  838. // Recursively sort each children if 'recurse' is true.
  839. //
  840. inline bool
  841. TTreeWindow::SortChildren(HTREEITEM item, bool recurse)
  842. {
  843.   return SendMessage(TVM_SORTCHILDREN, recurse, TParam2(item)) != 0;
  844. }
  845.  
  846. //
  847. // Return the root node.
  848. //
  849. inline TTreeNode
  850. TTreeWindow::GetRoot()
  851. {
  852.   return TTreeNode(*this);
  853. }
  854.  
  855. //
  856. // Compatability for Win32
  857. //
  858. inline void
  859. TTreeWindow::Update()
  860. {
  861. }
  862.  
  863. #endif  // BI_PLAT_WIN32
  864.  
  865. #endif  // OWL_TREEWIND_H
  866.